package com.cskaoyan.shopping.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.mall.dto.AllItemServiceResponse;
import com.cskaoyan.mall.dto.ProductDetailDto;
import com.cskaoyan.shopping.constants.ShoppingRetCode;
import com.cskaoyan.shopping.dto.AllProductResponse;
import com.cskaoyan.shopping.dto.PanelDto;
import com.cskaoyan.shopping.form.PageRequest;
import com.cskaoyan.shopping.service.IProductApiService;
import com.cskaoyan.shopping.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @Description
 * @Author klw
 * @Data 2022/12/2 下午9:40
 *
 * 该controller 搞定 商品模块 4-6 的接口
 */

@RestController
public class GoodsController {

    @Autowired
    IProductService productService;
    @Autowired
    IProductApiService productApiService;


    @GetMapping("/shopping/product/{id}")
    public ResponseData<Object> productDetail(@NotNull @PathVariable("id") Long id) {
        ProductDetailDto productDetail = productService.getProductDetail(id);
        return new ResponseUtil().setData(productDetail,"success");
    }


    @GetMapping("/shopping/goods")
    public ResponseData getGoodsList(PageRequest pageInfo) {
        AllProductResponse allProduct = productService.getAllProduct(pageInfo);
        return new ResponseUtil().setData(allProduct);
    }

    @GetMapping("/shopping/recommend")
    public ResponseData queryRecommendGoods() {
        List<PanelDto> recommendGoods = productService.getRecommendGoods();

        return new ResponseUtil().setData(recommendGoods);
    }
    @GetMapping("/rpc/items")
    AllItemServiceResponse getAllProductItem(){
        AllItemServiceResponse allItemServiceResponse = new AllItemServiceResponse();
        allItemServiceResponse.setCallData(productApiService.getAllProductItem());
        allItemServiceResponse.setCode(ShoppingRetCode.SUCCESS.getCode());
        allItemServiceResponse.setMsg(ShoppingRetCode.SUCCESS.getMessage());
        return allItemServiceResponse;
    }

}
